package com.cdu.guoxinan.www.smartcom.service.impl;

import com.cdu.guoxinan.www.smartcom.domian.vo.DashboardStatVo;
import com.cdu.guoxinan.www.smartcom.domian.vo.FeeVO;
import com.cdu.guoxinan.www.smartcom.domian.vo.StatisticsVo;
import com.cdu.guoxinan.www.smartcom.mapper.EmpStatisticsMapper;
import com.cdu.guoxinan.www.smartcom.service.EmpStatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

@Service
public class EmpStatisticsServiceImpl implements EmpStatisticsService {
    @Resource
    EmpStatisticsMapper empStatisticsMapper;
    @Override
    public List<StatisticsVo> feeTypeDistribution() {
        return empStatisticsMapper.feeTypeDistribution();
    }

    @Override
    public List<StatisticsVo> residentGenderDistribution() {
         return empStatisticsMapper.residentGenderDistribution();
    }

    @Override
    public List<StatisticsVo> propertyBuildingDistribution() {
         return empStatisticsMapper.propertyBuildingDistribution();
    }

    @Override
    public DashboardStatVo getDashboardStats() {
        DashboardStatVo vo = new DashboardStatVo();
        vo.setResidentCount(empStatisticsMapper.getResidentCount());
        // 当月订单数
        vo.setOrderCount(empStatisticsMapper.selectCurrentMonthOrderCount());
        int paid = empStatisticsMapper.countPaidFeesThisMonth();
        int total = empStatisticsMapper.countTotalFeesThisMonth();

        double rate = total == 0 ? 0.0 : (paid * 100.0 / total);
        vo.setFeeRate(Math.round(rate * 100.0) / 100.0); // 保留两位小数

        return vo;

    }

    @Override
    public List<StatisticsVo> monthlyFeeTrend() {
         return empStatisticsMapper.monthlyFeeTrend();
    }
    @Override
    public List<StatisticsVo> maintenanceTrend() {
        return empStatisticsMapper.maintenanceTrend();
    }
    @Override
    public List<StatisticsVo> complaintStatusDistribution() {
        return empStatisticsMapper.complaintStatusDistribution();
    }

    @Override
    public List<StatisticsVo> parkingStatusDistribution() {
        return empStatisticsMapper.parkingStatusDistribution();
    }

    @Override
    public List<StatisticsVo> topProducts() {
        return empStatisticsMapper.topProducts();
    }

    @Override
    public List<StatisticsVo> healthServicesDistribution() {
        return empStatisticsMapper.healthServicesDistribution();
    }

    public List<FeeVO> getFeeByName(String  name) {
        return empStatisticsMapper.getFeeByName(name);
    }

    public Long getResidentId(Long user_id) {return empStatisticsMapper.getResidentId(user_id);}
}
